package com.own.business.resource.core.util;

import com.own.constant.ConstantCommon;

import java.util.UUID;

/**
 * FileOnceUtil
 *
 * @author chenxueli
 * @date 2023-07-07 14:30:07
 */
public class FileOnceUtil {

    /**
     * 根据文件名称获取文件后缀
     *
     * @param fileName 文件名
     * @return 文件后缀
     */
    public static String getSuffix(String fileName) {
        if (fileName == null) {
            return "";
        }
        if (!fileName.contains(ConstantCommon.POINT)) {
            return "";
        }
        var suffix = fileName.substring(fileName.lastIndexOf(ConstantCommon.POINT)).toLowerCase();
        if (suffix.isEmpty()) {
            return "";
        }
        return suffix;
    }

    /**
     * 随机文件名
     *
     * @author chenxueli
     * @date 2021/9/17 15:45:00
     */
    public static String randomName(String suffix) {
        return UUID.randomUUID().toString().replaceAll("-", "") + suffix;
    }

}
